# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=jemalloc
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.1.0
pkgrel=1
pkgdesc="General-purpose scalable concurrent malloc implementation (mingw64)"
arch=('any')
url="http://www.canonware.com/jemalloc/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
source=(http://www.canonware.com/download/jemalloc/${_realname}-${pkgver}.tar.bz2
        001-fix-library-extension.patch
        002-makefile.patch)
sha256sums=('fad06d714f72adb4265783bc169c6d98eeb032d57ba02d87d1dcb4a2d933ec8e'
            '074700fcdb9d0548668d5e1f8a61b3571e35c839f45036146bb2e112ad5a5d9d'
            'bd9598d640f075b93159257614c35e011a3423e6fd4e171f560ee774224488e4')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-fix-library-extension.patch
  patch -p1 -i ${srcdir}/002-makefile.patch

  #./autogen.sh

}
build() {
  cd ${srcdir}/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  CFLAGS+=" -std=gnu11"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-autogen

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make DESTDIR=${pkgdir} install

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
